using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.IO;
using System.Runtime.CompilerServices;

namespace ClownFish
{
    public static class DbHelper
    {
        private static Func<string, DbContext> func_0 = new Func<string, DbContext>(DbHelper.smethod_0);

        [CompilerGenerated]
        private static CommandKind commandKind_0;

        public static Func<string, DbContext> CreateDefaultDbContext
        {
            get
            {
                return DbHelper.func_0;
            }
            set
            {
                if (value == null)
                {
                    throw new ArgumentNullException("value");
                }
                DbHelper.func_0 = value;
            }
        }

        public static CommandKind DefaultCommandKind
        {
            get;
            set;
        }

        private static DbContext smethod_0(string string_0)
        {
            return new DbContext(false);
        }

        public static void SetCommandParameters(this DbContext dbContext, object inputParams)
        {
            if (dbContext == null || dbContext.Connection == null || dbContext.CurrentCommand == null)
            {
                throw new ArgumentNullException("dbContext");
            }
            if (inputParams == null)
            {
                dbContext.class25_0 = null;
                return;
            }
            if (dbContext.CurrentCommand.Parameters.Count == 0 && dbContext.CurrentCommand.CommandType == CommandType.StoredProcedure)
            {
                DbParameter[] array = Class7.smethod_2(dbContext);
                DbParameter[] array2 = array;
                for (int i = 0; i < array2.Length; i++)
                {
                    DbParameter value = array2[i];
                    dbContext.CurrentCommand.Parameters.Add(value);
                }
            }
            if (dbContext.CurrentCommand.Parameters.Count == 0)
            {
                return;
            }
            int num = string.IsNullOrEmpty(dbContext.ParamNamePrefix) ? -1 : dbContext.CurrentCommand.Parameters[0].ParameterName.IndexOf(dbContext.ParamNamePrefix);
            IDictionary dictionary = inputParams as IDictionary;
            if (dictionary != null)
            {
                foreach (DbParameter dbParameter in dbContext.CurrentCommand.Parameters)
                {
                    if (dbParameter.Direction == ParameterDirection.Input || dbParameter.Direction == ParameterDirection.InputOutput)
                    {
                        dbParameter.ParameterName.Substring(num + 1);
                        dbParameter.Value = (dictionary[dbParameter] ?? DBNull.Value);
                    }
                }
                return;
            }
            inputParams.GetType().Assertion_Model();
            Class6 @class = inputParams.GetType().smethod_0(true);
            Class25 class2 = dbContext.AutoRetrieveOutputValues ? new Class25() : null;
            foreach (DbParameter dbParameter2 in dbContext.CurrentCommand.Parameters)
            {
                if (dbParameter2.Direction == ParameterDirection.Input || dbParameter2.Direction == ParameterDirection.InputOutput)
                {
                    string string_ = dbParameter2.ParameterName.Substring(num + 1);
                    Class34 class3 = null;
                    if (@class.method_11(string_, out class3))
                    {
                        dbParameter2.Value = (class3.method_4(inputParams) ?? DBNull.Value);
                    }
                }
                if (dbContext.AutoRetrieveOutputValues && (dbParameter2.Direction == ParameterDirection.Output || dbParameter2.Direction == ParameterDirection.InputOutput))
                {
                    class2.method_1(dbParameter2.ParameterName.Substring(num + 1));
                }
            }
            if (class2 != null && class2.method_0() != null && class2.method_0().Count > 0)
            {
                class2.object_0 = inputParams;
                dbContext.class25_0 = class2;
                return;
            }
            dbContext.class25_0 = null;
        }

        internal static void smethod_1(DbContext dbContext_0)
        {
            if (dbContext_0 == null || dbContext_0.class25_0 == null)
            {
                return;
            }
            Class25 class25_ = dbContext_0.class25_0;
            if (class25_.object_0 == null)
            {
                throw new InvalidOperationException("Internal Error, SpOutParamDescription.DataItem is null.");
            }
            Class6 @class = class25_.object_0.GetType().smethod_0(true);
            foreach (string current in class25_.method_0())
            {
                DbParameter commandParameter = dbContext_0.GetCommandParameter(current);
                if (commandParameter == null)
                {
                    throw new InvalidOperationException(string.Format("设置存储过程输出参数值失败，因为命令参数 [{0}] 不存在。", current));
                }
                Class34 class2 = null;
                if (!@class.method_11(current, out class2))
                {
                    throw new ArgumentOutOfRangeException(string.Format("设置存储过程输出参数值失败，因为实体成员 [{0}] 不存在。", current));
                }
                if (!class2.method_2().vmethod_4())
                {
                    throw new InvalidOperationException(string.Format("设置存储过程输出参数值失败，因为实体成员 [{0}] 不可写。", current));
                }
                if (!class2.method_5(class25_.object_0, commandParameter.Value))
                {
                    throw new InvalidOperationException(string.Format("设置存储过程输出参数值失败，因为写实体成员 [{0}] 失败。", current));
                }
            }
        }

        private static void smethod_2(DbContext dbContext_0, object object_0)
        {
            if (dbContext_0 != null && dbContext_0.Connection != null && dbContext_0.CurrentCommand != null)
            {
                if (object_0 == null)
                {
                    return;
                }
                IDictionary dictionary = object_0 as IDictionary;
                if (dictionary != null)
                {
                    foreach (DictionaryEntry dictionaryEntry in dictionary)
                    {
                        dbContext_0.AddParameterWithValue(dictionaryEntry.Key.ToString(), dictionaryEntry.Value);
                    }
                    return;
                }
                object_0.GetType().Assertion_Model();
                Class6 @class = object_0.GetType().smethod_0(true);
                using (Dictionary<string, Class34>.Enumerator enumerator2 = @class.method_8().GetEnumerator())
                {
                    while (enumerator2.MoveNext())
                    {
                        KeyValuePair<string, Class34> current = enumerator2.Current;
                        dbContext_0.AddParameterWithValue(current.Key, current.Value.method_2().vmethod_0(object_0));
                    }
                    return;
                }
            }
            throw new ArgumentNullException("dbContext");
        }

        private static void CreeateDBCommand(DbContext dbContext_0, string string_0, object object_0, CommandKind commandKind_1)
        {
            switch (commandKind_1)
            {
                case CommandKind.StoreProcedure:
                    dbContext_0.CreateCommand(string_0, CommandType.StoredProcedure);
                    break;
                //case CommandKind.XmlCommand:
                //	dbContext_0.CreateXmlCommand(string_0);
                //	break;
                case CommandKind.SqlTextNoParams:
                    dbContext_0.CreateCommand(string_0, CommandType.Text);
                    return;
                case CommandKind.SqlTextWithParams:
                    dbContext_0.CreateCommand(string_0, CommandType.Text);
                    DbHelper.smethod_2(dbContext_0, object_0);
                    return;
                default:
                    {
                        dbContext_0.CreateCommand(string_0, CommandType.StoredProcedure);
                        //XmlCommand command = XmlCommandManager.GetCommand(string_0);
                        //if (command != null)
                        //{
                        //	dbContext_0.method_0(command, string_0);
                        //}
                        //else
                        //{
                        //	
                        //}
                        break;
                    }
            }
            dbContext_0.SetCommandParameters(object_0);
        }

        private static void smethod_4(DbContext dbContext_0, CPQuery cpquery_0)
        {
            dbContext_0.CreateCommand(string.Empty, CommandType.Text);
            cpquery_0.BindToCommand(dbContext_0.CurrentCommand);
        }

        public static int ExecuteNonQuery(string nameOrSql, object inputParams)
        {
            return DbHelper.ExecuteNonQuery(nameOrSql, inputParams, DbHelper.DefaultCommandKind);
        }

        public static int ExecuteNonQuery(string nameOrSql, object inputParams, DbContext dbContext)
        {
            return DbHelper.ExecuteNonQuery(nameOrSql, inputParams, dbContext, DbHelper.DefaultCommandKind);
        }

        public static int ExecuteNonQuery(string nameOrSql, object inputParams, CommandKind cmdKind)
        {
            if (string.IsNullOrEmpty(nameOrSql))
            {
                throw new ArgumentNullException("nameOrSql");
            }
            int result;
            using (DbContext dbContext = DbHelper.func_0(nameOrSql))
            {
                result = DbHelper.ExecuteNonQuery(nameOrSql, inputParams, dbContext, cmdKind);
            }
            return result;
        }

        public static int ExecuteNonQuery(string nameOrSql, object inputParams, DbContext dbContext, CommandKind cmdKind)
        {
            if (dbContext == null)
            {
                throw new ArgumentNullException("dbContext");
            }
            if (string.IsNullOrEmpty(nameOrSql))
            {
                throw new ArgumentNullException("nameOrSql");
            }
            DbHelper.CreeateDBCommand(dbContext, nameOrSql, inputParams, cmdKind);
            return dbContext.ExecuteNonQuery();
        }

        public static int ExecuteNonQuery(this CPQuery query)
        {
            if (query == null)
            {
                throw new ArgumentNullException("query");
            }
            int result;
            using (DbContext dbContext = DbHelper.func_0(query.ToString()))
            {
                result = query.ExecuteNonQuery(dbContext);
            }
            return result;
        }

        public static int ExecuteNonQuery(this CPQuery query, DbContext dbContext)
        {
            if (dbContext == null)
            {
                throw new ArgumentNullException("dbContext");
            }
            if (query == null)
            {
                throw new ArgumentNullException("query");
            }
            DbHelper.smethod_4(dbContext, query);
            return dbContext.ExecuteNonQuery();
        }

        public static object ExecuteScalar(string nameOrSql, object inputParams)
        {
            return DbHelper.ExecuteScalar(nameOrSql, inputParams, DbHelper.DefaultCommandKind);
        }

        public static object ExecuteScalar(string nameOrSql, object inputParams, DbContext dbContext)
        {
            return DbHelper.ExecuteScalar(nameOrSql, inputParams, dbContext, DbHelper.DefaultCommandKind);
        }

        public static object ExecuteScalar(string nameOrSql, object inputParams, CommandKind cmdKind)
        {
            if (string.IsNullOrEmpty(nameOrSql))
            {
                throw new ArgumentNullException("name");
            }
            object result;
            using (DbContext dbContext = DbHelper.func_0(nameOrSql))
            {
                result = DbHelper.ExecuteScalar(nameOrSql, inputParams, dbContext, cmdKind);
            }
            return result;
        }

        public static object ExecuteScalar(string nameOrSql, object inputParams, DbContext dbContext, CommandKind cmdKind)
        {
            if (dbContext == null)
            {
                throw new ArgumentNullException("dbContext");
            }
            if (string.IsNullOrEmpty(nameOrSql))
            {
                throw new ArgumentNullException("nameOrSql");
            }
            DbHelper.CreeateDBCommand(dbContext, nameOrSql, inputParams, cmdKind);
            return dbContext.ExecuteScalar();
        }

        public static object ExecuteScalar(this CPQuery query)
        {
            if (query == null)
            {
                throw new ArgumentNullException("query");
            }
            object result;
            using (DbContext dbContext = DbHelper.func_0(query.ToString()))
            {
                result = query.ExecuteScalar(dbContext);
            }
            return result;
        }

        public static object ExecuteScalar(this CPQuery query, DbContext dbContext)
        {
            if (dbContext == null)
            {
                throw new ArgumentNullException("dbContext");
            }
            if (query == null)
            {
                throw new ArgumentNullException("query");
            }
            DbHelper.smethod_4(dbContext, query);
            return dbContext.ExecuteScalar();
        }

        internal static T smethod_5<T>(object object_0)
        {
            if (object_0 != null && !DBNull.Value.Equals(object_0))
            {
                return (T)((object)Convert.ChangeType(object_0, typeof(T)));
            }
            return default(T);
        }

        public static T ExecuteScalar<T>(string nameOrSql, object inputParams)
        {
            return DbHelper.smethod_5<T>(DbHelper.ExecuteScalar(nameOrSql, inputParams));
        }

        public static T ExecuteScalar<T>(string nameOrSql, object inputParams, DbContext dbContext)
        {
            return DbHelper.smethod_5<T>(DbHelper.ExecuteScalar(nameOrSql, inputParams, dbContext));
        }

        public static T ExecuteScalar<T>(string nameOrSql, object inputParams, CommandKind cmdKind)
        {
            return DbHelper.smethod_5<T>(DbHelper.ExecuteScalar(nameOrSql, inputParams, cmdKind));
        }

        public static T ExecuteScalar<T>(string nameOrSql, object inputParams, DbContext dbContext, CommandKind cmdKind)
        {
            return DbHelper.smethod_5<T>(DbHelper.ExecuteScalar(nameOrSql, inputParams, dbContext, cmdKind));
        }

        public static T ExecuteScalar<T>(this CPQuery query)
        {
            return DbHelper.smethod_5<T>(query.ExecuteScalar());
        }

        public static T ExecuteScalar<T>(this CPQuery query, DbContext dbContext)
        {
            return DbHelper.smethod_5<T>(query.ExecuteScalar(dbContext));
        }

        public static T GetDataItem<T>(string nameOrSql, object inputParams) where T : class, new()
        {
            return DbHelper.GetDataItem<T>(nameOrSql, inputParams, DbHelper.DefaultCommandKind);
        }

        public static T GetDataItem<T>(string nameOrSql, object inputParams, DbContext dbContext) where T : class, new()
        {
            return DbHelper.GetDataItem<T>(nameOrSql, inputParams, dbContext, DbHelper.DefaultCommandKind);
        }

        public static T GetDataItem<T>(string nameOrSql, object inputParams, CommandKind cmdKind) where T : class, new()
        {
            if (string.IsNullOrEmpty(nameOrSql))
            {
                throw new ArgumentNullException("nameOrSql");
            }
            T dataItem;
            using (DbContext dbContext = DbHelper.func_0(nameOrSql))
            {
                dataItem = DbHelper.GetDataItem<T>(nameOrSql, inputParams, dbContext, cmdKind);
            }
            return dataItem;
        }

        public static T GetDataItem<T>(string nameOrSql, object inputParams, DbContext dbContext, CommandKind cmdKind) where T : class, new()
        {
            if (dbContext == null)
            {
                throw new ArgumentNullException("dbContext");
            }
            if (string.IsNullOrEmpty(nameOrSql))
            {
                throw new ArgumentNullException("nameOrSql");
            }
            DbHelper.CreeateDBCommand(dbContext, nameOrSql, inputParams, cmdKind);
            return dbContext.GetDataItem<T>();
        }

        public static T GetDataItem<T>(this CPQuery query) where T : class, new()
        {
            if (query == null)
            {
                throw new ArgumentNullException("query");
            }
            T dataItem;
            using (DbContext dbContext = DbHelper.func_0(query.ToString()))
            {
                dataItem = query.GetDataItem<T>(dbContext);
            }
            return dataItem;
        }

        public static T GetDataItem<T>(this CPQuery query, DbContext dbContext) where T : class, new()
        {
            if (dbContext == null)
            {
                throw new ArgumentNullException("dbContext");
            }
            if (query == null)
            {
                throw new ArgumentNullException("query");
            }
            DbHelper.smethod_4(dbContext, query);
            return dbContext.GetDataItem<T>();
        }

        public static List<T> FillList<T>(string nameOrSql, object inputParams) where T : class, new()
        {
            return DbHelper.FillList<T>(nameOrSql, inputParams, DbHelper.DefaultCommandKind);
        }

        public static List<T> FillList<T>(string nameOrSql, object inputParams, DbContext dbContext) where T : class, new()
        {
            return DbHelper.FillList<T>(nameOrSql, inputParams, dbContext, DbHelper.DefaultCommandKind);
        }

        public static List<T> FillList<T>(string nameOrSql, object inputParams, CommandKind cmdKind) where T : class, new()
        {
            if (string.IsNullOrEmpty(nameOrSql))
            {
                throw new ArgumentNullException("nameOrSql");
            }
            List<T> result;
            using (DbContext dbContext = DbHelper.func_0(nameOrSql))
            {
                result = DbHelper.FillList<T>(nameOrSql, inputParams, dbContext, cmdKind);
            }
            return result;
        }

        public static List<T> FillList<T>(string nameOrSql, object inputParams, DbContext dbContext, CommandKind cmdKind) where T : class, new()
        {
            if (dbContext == null)
            {
                throw new ArgumentNullException("dbContext");
            }
            if (string.IsNullOrEmpty(nameOrSql))
            {
                throw new ArgumentNullException("name");
            }
            DbHelper.CreeateDBCommand(dbContext, nameOrSql, inputParams, cmdKind);
            DbHelper.IniListCapacity(dbContext, inputParams);
            return dbContext.FillList<T>();
        }


        public static DbDataReader GetReader(string nameOrSql, object inputParams, DbContext dbContext, CommandKind cmdKind)
        {
            if (dbContext == null)
            {
                throw new ArgumentNullException("dbContext");
            }
            if (string.IsNullOrEmpty(nameOrSql))
            {
                throw new ArgumentNullException("name");
            }
            DbHelper.CreeateDBCommand(dbContext, nameOrSql, inputParams, cmdKind);
            DbHelper.IniListCapacity(dbContext, inputParams);
            return dbContext.ExecuteDataReader();
        }



        private static void IniListCapacity(DbContext dbContext_0, object object_0)
        {
            PagingInfo pagingInfo = object_0 as PagingInfo;
            if (pagingInfo == null)
            {
                dbContext_0.ListIniCapacity = DbContextDefaultSetting.ListResultCapacity;
                return;
            }
            dbContext_0.ListIniCapacity = pagingInfo.PageSize;
        }

        public static List<T> FillList<T>(this CPQuery query) where T : class, new()
        {
            if (query == null)
            {
                throw new ArgumentNullException("query");
            }
            List<T> result;
            using (DbContext dbContext = DbHelper.func_0(query.ToString()))
            {
                result = query.FillList<T>(dbContext);
            }
            return result;
        }

        public static List<T> FillList<T>(this CPQuery query, DbContext dbContext) where T : class, new()
        {
            if (dbContext == null)
            {
                throw new ArgumentNullException("dbContext");
            }
            if (query == null)
            {
                throw new ArgumentNullException("query");
            }
            DbHelper.smethod_4(dbContext, query);
            return dbContext.FillList<T>();
        }


        public static List<T> FillListPaged<T>(string nameOrSql, PagingInfo inputParams) where T : class, new()
        {
            return DbHelper.FillListPaged<T>(nameOrSql, inputParams, DbHelper.DefaultCommandKind);
        }

        public static List<T> FillListPaged<T>(string nameOrSql, PagingInfo inputParams, DbContext dbContext) where T : class, new()
        {
            return DbHelper.FillListPaged<T>(nameOrSql, inputParams, dbContext, DbHelper.DefaultCommandKind);
        }

        public static List<T> FillListPaged<T>(string nameOrSql, PagingInfo inputParams, CommandKind cmdKind) where T : class, new()
        {
            if (string.IsNullOrEmpty(nameOrSql))
            {
                throw new ArgumentNullException("nameOrSql");
            }
            if (inputParams == null)
            {
                throw new ArgumentNullException("inputParams");
            }
            List<T> result;
            using (DbContext dbContext = DbHelper.func_0(nameOrSql))
            {
                result = DbHelper.FillListPaged<T>(nameOrSql, inputParams, dbContext, cmdKind);
            }
            return result;
        }

        public static List<T> FillListPaged<T>(string nameOrSql, PagingInfo inputParams, DbContext dbContext, CommandKind cmdKind) where T : class, new()
        {
            if (dbContext == null)
            {
                throw new ArgumentNullException("dbContext");
            }
            if (string.IsNullOrEmpty(nameOrSql))
            {
                throw new ArgumentNullException("nameOrSql");
            }
            if (inputParams == null)
            {
                throw new ArgumentNullException("inputParams");
            }
            bool autoRetrieveOutputValues = dbContext.AutoRetrieveOutputValues;
            List<T> result;
            try
            {
                if (!autoRetrieveOutputValues)
                {
                    dbContext.AutoRetrieveOutputValues = true;
                }
                DbHelper.CreeateDBCommand(dbContext, nameOrSql, inputParams, cmdKind);
                DbHelper.IniListCapacity(dbContext, inputParams);
                List<T> list = dbContext.FillList<T>();
                if (list.Count == 0 && inputParams.PageIndex > 0 && inputParams.TotalRecords > 0)
                {
                    DbParameter commandParameter = dbContext.GetCommandParameter(DbContext.STR_PageIndex);
                    if (commandParameter != null)
                    {
                        commandParameter.Value = 0;
                        inputParams.PageIndex = 0;
                        list = dbContext.FillList<T>();
                    }
                }
                result = list;
            }
            finally
            {
                dbContext.AutoRetrieveOutputValues = autoRetrieveOutputValues;
            }
            return result;
        }

        public static List<T> FillScalarList<T>(string nameOrSql, object inputParams)
        {
            return DbHelper.FillScalarList<T>(nameOrSql, inputParams, DbHelper.DefaultCommandKind);
        }

        public static List<T> FillScalarList<T>(string nameOrSql, object inputParams, DbContext dbContext)
        {
            return DbHelper.FillScalarList<T>(nameOrSql, inputParams, dbContext, DbHelper.DefaultCommandKind);
        }

        public static List<T> FillScalarList<T>(string nameOrSql, object inputParams, CommandKind cmdKind)
        {
            if (string.IsNullOrEmpty(nameOrSql))
            {
                throw new ArgumentNullException("nameOrSql");
            }
            List<T> result;
            using (DbContext dbContext = DbHelper.func_0(nameOrSql))
            {
                result = DbHelper.FillScalarList<T>(nameOrSql, inputParams, dbContext, cmdKind);
            }
            return result;
        }

        public static List<T> FillScalarList<T>(string nameOrSql, object inputParams, DbContext dbContext, CommandKind cmdKind)
        {
            if (dbContext == null)
            {
                throw new ArgumentNullException("dbContext");
            }
            if (string.IsNullOrEmpty(nameOrSql))
            {
                throw new ArgumentNullException("name");
            }
            DbHelper.CreeateDBCommand(dbContext, nameOrSql, inputParams, cmdKind);
            DbHelper.IniListCapacity(dbContext, inputParams);
            return dbContext.FillScalarList<T>();
        }

        public static List<T> FillScalarList<T>(this CPQuery query)
        {
            if (query == null)
            {
                throw new ArgumentNullException("query");
            }
            List<T> result;
            using (DbContext dbContext = DbHelper.func_0(query.ToString()))
            {
                result = query.FillScalarList<T>(dbContext);
            }
            return result;
        }

        public static List<T> FillScalarList<T>(this CPQuery query, DbContext dbContext)
        {
            if (dbContext == null)
            {
                throw new ArgumentNullException("dbContext");
            }
            if (query == null)
            {
                throw new ArgumentNullException("query");
            }
            DbHelper.smethod_4(dbContext, query);
            return dbContext.FillScalarList<T>();
        }

        public static Guid NewSequentialGuid()
        {
            byte[] array = Guid.NewGuid().ToByteArray();
            DateTime dateTime = new DateTime(1900, 1, 1);
            DateTime now = DateTime.Now;
            TimeSpan timeSpan = new TimeSpan(now.Date.Ticks - dateTime.Ticks);
            TimeSpan timeSpan2 = new TimeSpan(now.Ticks - now.Date.Ticks);
            byte[] bytes = BitConverter.GetBytes(timeSpan.Days);
            byte[] bytes2 = BitConverter.GetBytes((long)(timeSpan2.TotalMilliseconds / 3.333333));
            Array.Reverse(bytes);
            Array.Reverse(bytes2);
            for (int i = 15; i >= 6; i--)
            {
                array[i] = array[i - 6];
            }
            Array.Copy(bytes, bytes.Length - 2, array, 0, 2);
            Array.Copy(bytes2, bytes2.Length - 4, array, 2, 4);
            return new Guid(array);
        }

        public static string[] GetColumnNames(this DbDataReader reader)
        {
            int fieldCount = reader.FieldCount;
            string[] array = new string[fieldCount];
            for (int i = 0; i < fieldCount; i++)
            {
                array[i] = reader.GetName(i);
            }
            return array;
        }

        public static string[] GetColumnNames(this DataTable table)
        {
            string[] array = new string[table.Columns.Count];
            for (int i = 0; i < table.Columns.Count; i++)
            {
                array[i] = table.Columns[i].ColumnName;
            }
            return array;
        }

        public static List<T> FillListFromXmlFile<T>(string xmlPath) where T : class, new()
        {
            if (!File.Exists(xmlPath))
            {
                return null;
            }
            DataSet dataSet = new DataSet();
            dataSet.ReadXml(xmlPath);
            if (dataSet.Tables.Count == 0)
            {
                return null;
            }
            return DbHelper.FillListFromTable<T>(dataSet.Tables[0]);
        }

        public static List<T> FillListFromTable<T>(DataTable table) where T : class, new()
        {
            if (table == null)
            {
                throw new ArgumentNullException("table");
            }
            if (table.Rows.Count == 0)
            {
                return new List<T>();
            }
            Delegate0 @delegate = typeof(T).smethod_0(true).method_0();
            if (@delegate == null)
            {
                List<T> list = new List<T>(table.Rows.Count);
                Class9 @class = new Class9(table.Rows[0]);
                foreach (DataRow object_ in table.Rows)
                {
                    @class.method_2(object_);
                    T t = Activator.CreateInstance(typeof(T)) as T;
                    Class30.smethod_2(@class, t);
                    list.Add(t);
                }
                return list;
            }
            return (List<T>)@delegate(Class28.int_3, table, table.Rows.Count);
        }

        public static DataTable FillDataTable(string nameOrSql, object inputParams)
        {
            return DbHelper.FillDataTable(nameOrSql, inputParams, DbHelper.DefaultCommandKind);
        }

        public static DataTable FillDataTable(string nameOrSql, object inputParams, DbContext dbContext)
        {
            return DbHelper.FillDataTable(nameOrSql, inputParams, dbContext, DbHelper.DefaultCommandKind);
        }

        public static DataTable FillDataTable(string nameOrSql, object inputParams, CommandKind cmdKind)
        {
            if (string.IsNullOrEmpty(nameOrSql))
            {
                throw new ArgumentNullException("name");
            }
            DataTable result;
            using (DbContext dbContext = DbHelper.func_0(nameOrSql))
            {
                result = DbHelper.FillDataTable(nameOrSql, inputParams, dbContext, cmdKind);
            }
            return result;
        }

        public static DataTable FillDataTable(string nameOrSql, object inputParams, DbContext dbContext, CommandKind cmdKind)
        {
            if (dbContext == null)
            {
                throw new ArgumentNullException("dbContext");
            }
            if (string.IsNullOrEmpty(nameOrSql))
            {
                throw new ArgumentNullException("nameOrSql");
            }
            DbHelper.CreeateDBCommand(dbContext, nameOrSql, inputParams, cmdKind);
            return dbContext.FillDataTable();
        }

        public static DataTable FillDataTable(this CPQuery query)
        {
            if (query == null)
            {
                throw new ArgumentNullException("query");
            }
            DataTable result;
            using (DbContext dbContext = DbHelper.func_0(query.ToString()))
            {
                result = query.FillDataTable(dbContext);
            }
            return result;
        }

        public static DataTable FillDataTable(this CPQuery query, DbContext dbContext)
        {
            if (dbContext == null)
            {
                throw new ArgumentNullException("dbContext");
            }
            if (query == null)
            {
                throw new ArgumentNullException("query");
            }
            DbHelper.smethod_4(dbContext, query);
            return dbContext.FillDataTable();
        }


        public static DataSet FillDataSet(string nameOrSql, object inputParams, DbContext dbContext, CommandKind cmdKind, params string[] tableNames)
        {
            if (dbContext == null)
            {
                throw new ArgumentNullException("dbContext");
            }
            if (string.IsNullOrEmpty(nameOrSql))
            {
                throw new ArgumentNullException("nameOrSql");
            }
            DbHelper.CreeateDBCommand(dbContext, nameOrSql, inputParams, cmdKind);
            return dbContext.FillDataSet(tableNames);
        }


    }
}
